<template>
	<view class="page">
		<free-nav-bar showback showright="true" title="设置备注和标签">

			<view slot="right" class="main-bg-color rounded mr-3 px-2 py-1">
				<text class="font text-white" @click="finish">完成</text>


			</view>
		</free-nav-bar>

		<view class="flex flex-column">
			<text class="font-sm text-secondary px-3 py-2">备注名</text>
			<input type="text" style="height: 100rpx;" v-model="nickname" class="font-md px-3 border bg-white"
				placeholder="请输入备注名">
		</view>

		<view class="flex flex-column">
			<text class="font-sm text-secondary px-3 py-2">标签</text>
			<view style="" class="font-md px-3 border bg-white flex flex-wrap align-center py-3" @click="opentag">

				<view class="border border-main main-text-color rounded-circle px-2 py-1 mr-1 mb-1 "
					v-for="item in tagList">
					<text class="main-text-color">{{item}}</text>
				</view>
			</view>
		</view>
		<!-- <view v-if="text!==''" class="main-bg-color rounded mr-3 px-2 py-1" @click="send('text')">
			<text class="font text-white">发送</text>
		
		
		</view> -->
	</view>
</template>

<script>
	import $H from '../../../utils/request.js';
	import freeNavBar from "@/components/free-ui/free-nav-bar.vue"
	export default {
		components: {
			freeNavBar
		},
		data() {
			return {
				nickname: "",
				id: "",
				detail: {},
				tagList: [],
			}
		},
		onLoad(e) {

			console.log(e, "e")
			let params = JSON.parse(e.params)
			this.id = params.id
			this.nickname = params.nickname
			this.tagList = params.tags
			uni.$on('updateTag', e => {
				console.log(e, "e");

				this.tagList = JSON.parse(e)
			})
		},
		destroyed() {
			uni.$off("updateTag")
		},
		methods: {
			finish() {
				// uni.$emit("setTag", JSON.stringify(this.tagList))
				// uni.navigateBack({
				// 	delta: 1
				// })
				$H.post("friend/setrearktag/" + this.id, {
					nickname: this.nickname,
					tags: this.tagList.join(",")
				}, {
					token: true
				}).then(res => {
					if(res){
						
					uni.navigateBack({
						delta: 1
					})
											
					}

				})
			},
			opentag() {
				uni.navigateTo({
					url: "/pages/mail/userTagSet/userTagSet?detail=" + JSON.stringify(this.tagList)
				})
			}
		}
	}
</script>

<style>

</style>
